
/**
 *
 */
public class Ship
{
	public final static int ORIENTATION_UP = 0;
	public final static int ORIENTATION_RIGHT = 1;
	public final static int ORIENTATION_DOWN = 2;
	public final static int ORIENTATION_LEFT = 3;
	public final static int MAX_ORIENTATIONS = 4;
	
    public int locationX, locationY;
    public int orientation; //0 = up, 1 = right, 2 = down, 3 = left
    private int length;

    public Ship(int length)
    {
        this.length = length;
    }
    
    public Ship(int locationX, int locationY, int orientation, int length)
    {
        this.locationX = locationX;
        this.locationY = locationY;
        this.orientation = orientation;
        this.length = length;
    }
    
    public Ship(Ship otherShip)
    {
        this.locationX = otherShip.locationX;
        this.locationY = otherShip.locationY;
        this.orientation = otherShip.orientation;
        this.length = otherShip.length;
    }
    
    //Equals checks for equivalent orientation/location combinations on board
    public boolean equivalent(Ship otherShip)
    {
        //Length does not match
        if (this.length != otherShip.length)
            return false;
        
        //Compare ships of length 1
        if (this.length == 1)
        {
            if (this.locationX == otherShip.locationX
                    && this.locationY == otherShip.locationY)
                return true;
            else
                return false;
        }
        
        //Simple case
        if (this.locationX == otherShip.locationX
                && this.locationY == otherShip.locationY
                && this.orientation == otherShip.orientation)
        {
            return true;
        }
        //Ship orientation/locations are equivalent
        else if (this.orientation == Ship.ORIENTATION_DOWN && otherShip.orientation == Ship.ORIENTATION_UP)
        {
            if (this.locationX != otherShip.locationX)
                return false;
            
            if (this.locationY == otherShip.locationY - (this.length-1))
                return true;
        }
        else if (this.orientation == Ship.ORIENTATION_UP && otherShip.orientation == Ship.ORIENTATION_DOWN)
        {
            if (this.locationX != otherShip.locationX)
                return false;
            
            if (this.locationY == otherShip.locationY + (this.length-1))
                return true;
        }
        else if (this.orientation == Ship.ORIENTATION_LEFT && otherShip.orientation == Ship.ORIENTATION_RIGHT)
        {
            if (this.locationY != otherShip.locationY)
                return false;
            
            if (this.locationX == otherShip.locationX + (this.length-1))
                return true;
        }
        else if (this.orientation == Ship.ORIENTATION_RIGHT && otherShip.orientation == Ship.ORIENTATION_LEFT)
        {
            if (this.locationY != otherShip.locationY)
                return false;
            
            if (this.locationX == otherShip.locationX - (this.length-1))
                return true;
        }
        
        return false;
    }
    
    public int getLength()
    {
    	return this.length;
    }
}
